import { Menu, BrowserWindow, MenuItemConstructorOptions, MenuItem, shell } from 'electron'

export default (window: BrowserWindow): void => {
  // window.webContents.executeJavaScript("location.hash = '/print'")
  // ElectronMenu.js
  // 设置菜单栏, win表示当前窗口实例
  const template: Array<(MenuItemConstructorOptions) | (MenuItem)> = [{
    label: '功能',
    submenu: [
      { label: '打印', accelerator: 'CmdOrCtrl+P', click: () => { window.webContents.executeJavaScript("location.hash = '/print'") } },
      { label: '返回', accelerator: 'CmdOrCtrl+B', click: () => { window.webContents.goBack() } },
      { label: '刷新', accelerator: 'CmdOrCtrl+R', click: () => { window.reload() } },
      { label: 'bee', accelerator: 'CmdOrCtrl+L', click: () => { shell.beep() } }
    ]
  },
  {
    label: '编辑',
    submenu: [{ label: '复制', accelerator: 'CmdOrCtrl+C', role: 'copy' },
    { label: '粘贴', accelerator: 'CmdOrCtrl+V', role: 'paste' }, { label: '剪切', accelerator: 'CmdOrCtrl+X', role: 'cut' },
    { label: '撤销', accelerator: 'CmdOrCtrl+Z', role: 'undo' }, { label: '重做', accelerator: 'CmdOrCtrl+Y', role: 'redo' },
    { label: '全选', accelerator: 'CmdOrCtrl+A', role: 'selectAll' }]
  }, {
    label: '窗口',
    role: 'window',
    submenu: [{ label: '全屏', role: 'togglefullscreen' },
    { label: '最小化', role: 'minimize' }, { label: '关闭', role: 'close' }]
  }, {
    label: '帮助',
    role: 'help',
    submenu: [
      { label: '检测更新', click: () => { window.webContents.send('menuCheckUpdate') }, accelerator: 'CmdOrCtrl+U', enabled: false },
      { label: '开发者工具', role: 'toggleDevTools', accelerator: 'CmdOrCtrl+F12' },
      { label: '百度一下', accelerator: 'CmdOrCtrl+Q', click: () => { shell.openExternal('https://baidu.com') } },
      { label: '关于', accelerator: 'CmdOrCtrl+I', role: 'about', type: 'normal' }
    ]
  }]
  const menu = Menu.buildFromTemplate(template)
  Menu.setApplicationMenu(menu)
}
